<?php
	if(isset($_GET['id']) && isset($_GET['pin']))
	{
		$MaHocVien = trim($_GET['id']);
		$PIN       = trim($_GET['pin']);
		include_once '../classes/hocvien_bs.php';
		
		$HocVien = new hocvien_bs();
		$HocVien->SetMaHocVien($MaHocVien);
		$DHocVien = $HocVien->LayDanhSach();
		if($DHocVien == null)
			header('Location: index.php?act=hocvien');
		elseif(trim($DHocVien[0]['PIN']) == $PIN)
		{
			include_once '../classes/chuongtrinhhoc_bs.php';
			include_once '../classes/thoigianhoc_bs.php';
			include_once '../classes/khoahoc_bs.php';
			include_once '../classes/lophoc_bs.php';
			include_once '../classes/phonghoc_bs.php';
			include_once '../classes/giaovien_bs.php';
			
			$ChuongTrinhHoc = new chuongtrinhhoc_bs();
			$DChuongTrinhHoc = $ChuongTrinhHoc->LayDanhSach();
			
			$ThoiGianHoc = new thoigianhoc_bs();
			$DThoiGianHoc = $ThoiGianHoc->LayDanhSach();
			
			$LopHoc = new lophoc_bs();
			$DLopHoc = $LopHoc->LayDanhSach();
			
?>
	<div class="FormCapNhat">
		<form action="index.php?act=hocvien_capnhat_sub" method="POST">
			<div class="Title">
				Cập nhật thông tin học viên
				<div style="float:right">
					<a href="index.php?act=hocvien">Xem danh sách</a>
				</div>
			</div>
			
			<div class="Left">
				<table width="100%">
					<tr>
						<th colspan="2">Thông tin cá nhân</th>
					</tr>
					<tr>
						<td width="20%">Mã học viên</td>
						<td><input name="MaHocVien" type="text" readonly="true" value="<?php echo $DHocVien[0]['MaHocVien']; ?>"/></td>
					</tr>
					<tr>
						<td>Họ tên</td>
						<td><input name="HoTen" style="font-weight:bold" type="text" value="<?php echo $DHocVien[0]['HoTen']; ?>"/></td>
					</tr>
					<tr>
						<td>Ngày sinh</td>
						<td><input name="NgaySinh" type="text" id="datepicker" value="<?php echo ConvertDate($DHocVien[0]['NgaySinh']); ?>"/></td>
					</tr>
					<tr>
						<td>Giới tính</td>
						<?php
							if($DHocVien[0]['GioiTinh'] == 0)
							{
								$NavCheckNam = 'checked="checked"';
								$NavCheckNu  = '';
							}
							else
							{
								$NavCheckNam = '';
								$NavCheckNu  = 'checked="checked"';
							}
						?>
						<td>
							<input type="radio" id="radioNam" name="GioiTinh" class="css-radio" <?php echo $NavCheckNam; ?>/>
							<label for="radioNam" class="css-labelRadio">Nam</label>
							<input type="radio" id="radioNu" name="GioiTinh" class="css-radio" <?php echo $NavCheckNu; ?>/>
							<label for="radioNu" class="css-labelRadio">Nữ</label>
						</td>
					</tr>
					<tr>
						<td>Địa chỉ</td>
						<td><input name="DiaChi" type="text" value="<?php echo $DHocVien[0]['DiaChi']; ?>"/></td>
					</tr>
					<tr>
						<td>Điện thoại</td>
						<td><input name="DienThoai" type="text" value="<?php echo $DHocVien[0]['DienThoai']; ?>"/></td>
					</tr>
					<tr>
						<td>Email</td>
						<td><input name="Email" type="text" value="<?php echo $DHocVien[0]['Email']; ?>"/></td>
					</tr>
					<tr>
						<td>Lớp (ĐHAG)</td>
						<td><input name="Lop" type="text" value="<?php echo $DHocVien[0]['Lop']; ?>"/></td>
					</tr>
				</table>
				<table width="100%">
					<tr>
						<th colspan="2">Thông tin đăng ký</th>
					</tr>
					<tr>
						<td width="30%">Ngày đăng ký</td>
						<td>
							<input name="NgayDangKy" type="text" readonly="true" value="<?php echo ConvertDate($DHocVien[0]['NgayDangKy']); ?>" />
						</td>
					</tr>
					<tr>
						<td>Chương trình</td>
						<td>
							<select id="" name="MaChuongTrinh">
								<?php
									for($i = 0; $i < count($DChuongTrinhHoc); $i++)
									{
										if($DChuongTrinhHoc[$i]['MaChuongTrinh'] == $DHocVien[0]['MaChuongTrinh'])
											$tmp = 'selected="true"';
										else
											$tmp = '';
										echo '<option ' . $tmp . ' value="' . $DChuongTrinhHoc[$i]['MaChuongTrinh'] . '">' . $DChuongTrinhHoc[$i]['TenChuongTrinh'] . '</option>';
									}
								?>
							</select>
						</td>
					</tr>
					<tr>
						<td>Thời gian học</td>
						<td>
							<select name="MaThoiGianHoc" id="">
								<?php
									for($i = 0; $i < count($DThoiGianHoc); $i++)
									{
										if($DThoiGianHoc[$i]['MaThoiGianHoc'] == $DHocVien[0]['MaThoiGianHoc'])
											$tmp = 'selected="true"';
										else
											$tmp = '';
										echo '<option ' . $tmp . ' value="' . $DThoiGianHoc[$i]['MaThoiGianHoc'] . '">' . $DThoiGianHoc[$i]['ChuThich'] . '</option>';
									}
								?>
							</select>
						</td>
					</tr>
				</table>
			</div>
			<div class="Right">
				
				<table width="100%">
					<tr>
						<th colspan="2">CICT</th>
					</tr>
					<tr>
						<td width="35%">Lớp học</td>
						<td>
							<select name="MaLopHoc" id="">
								<?php
									for($i = 0; $i < count($DLopHoc); $i++)
									{
										if($DLopHoc[$i]['MaLopHoc'] == $DHocVien[0]['MaLopHoc'])
											$tmp = 'selected="true"';
										else
											$tmp = '';
										echo '<option ' . $tmp . ' value="' . $DLopHoc[$i]['MaLopHoc'] . '">' . ($DLopHoc[$i]['MaLopHoc'] == "0" ? "Chưa xếp lớp" : $DLopHoc[$i]['MaLopHoc']) . '</option>';
									}
								?>
							</select>
						</td>
					</tr>
					<tr>
						<td>Phòng học</td>
						<td>
							<?php
								$LopHoc = new lophoc_bs();
								$LopHoc->SetMaLopHoc($DHocVien[0]['MaLopHoc']);
								$DLopHoc = $LopHoc->LayDanhSach();
								
								$PhongHoc = new phonghoc_bs();
								$PhongHoc->SetMaPhong($DLopHoc[0]['MaPhong']);
								$DPhongHoc = $PhongHoc->LayDanhSach();
							?>
							<input type="text" readonly="true" value="<?php echo ($DHocVien[0]['MaLopHoc'] == "0" ? "-" : $DPhongHoc[0]['TenPhong']); ?>"/>
						</td>
					</tr>
					<tr>
						<td>Số máy</td>
						<td>
							<input name="SoMay" type="text" value="<?php echo $DHocVien[0]['SoMay']; ?>" />
						</td>
					</tr>
				</table>
				<table width="100%">
					<tr>
						<th colspan="2">Học phí</th>
					</tr>
					<tr>
						<td width="35%">Học phí</td>
						<?php
							$ChuongTrinhHoc = new chuongtrinhhoc_bs();
							$ChuongTrinhHoc->SetMaChuongTrinh($DHocVien[0]['MaChuongTrinh']);
							$DChuongTrinhHoc = $ChuongTrinhHoc->LayDanhSach();
						?>
						<td>
							<input type="text" readonly="true" value="<?php echo $DChuongTrinhHoc[0]['HocPhi']; ?>"/>
						</td>
					</tr>
					<tr>
						<td>Được giảm (%)</td>
						<td>
							<input name="HocPhiDuocGiam" type="text" placeholder="Tính bằng %" value="<?php echo $DHocVien[0]['HocPhiDuocGiam'] ; ?>"/>
						</td>
					</tr>
					<tr>
						<td>Đã nộp</td>
						<td>
							<input name="HocPhiDaNop" type="text" readonly="true" placeholder="Tính bằng %" value="<?php echo $DHocVien[0]['HocPhiDaNop'] ; ?>"/>
						</td>
					</tr>
					<tr>
						<td>Phải nộp</td>
						<td>
							<input type="text" readonly="true" placeholder="Tính bằng %" value="<?php echo ($DChuongTrinhHoc[0]['HocPhi'] * (1 - $DHocVien[0]['HocPhiDuocGiam']) - $DHocVien[0]['HocPhiDaNop']) ; ?>"/>
						</td>
					</tr>
				</table>
			</div>
			
			<div class="Bottom">
				<table width="100%">
					<tr>
						<td width="50%" align="right"> <input type="submit" class="SubmitButton" onclick="return confirm('Bạn có chắc cập nhật?')" value="Cập nhật"/></td>
						<td width="50%"> <input type="reset" class="ResetButton" value="Đặt lại"/></td>
					</tr>
				</table>
			</div>
		</form>
	</div>
<?php
		}
		else
			header('Location: index.php?act=hocvien');
	}
	else
	{
		header('Location: index.php?act=hocvien');
	}